package operator.combine;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import util.Printer;

class StartWithOperator {

    public static void main(String[] args) {
        startWith();
        startWithArray();
    }

    /***
     * 在发送事件之前追加事件，startWith() 追加一个事件，startWithArray() 可以追加多个事件，追加的事件会先发出
     */
    static void startWith(){
        Observable.just(4, 5)
                .startWith(1)
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Printer.print("startWith integer = " + integer);
                    }
                });
    }

    static void startWithArray(){
        Observable.just(4, 5)
                .startWithArray(2, 3)
                .startWith(1)
                .startWith(0)
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        Printer.print("startWithArray integer = " + integer);
                    }
                });
    }


}
